package com.pactera.miyuangroup.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.pactera.miyuangroup.db.entity.LoginUser;
import com.pactera.miyuangroup.service.LoginUserService;
import com.pactera.miyuangroup.vo.response.ResultStatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.UUID;

import static java.util.Collections.emptyList;

/**
 * 用户登录
 *
 * @author Wangwu
 * @create 2018-04-02 上午10:12
 **/
@Service
@Slf4j
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;
    @Autowired
    private LoginUserService loginUserService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

//        EntityWrapper<LoginUser> ew = new EntityWrapper<LoginUser>();
//        ew.eq("user_name", username);
//        LoginUser loginUser = loginUserService.selectOne(ew);
//        if (null == loginUser) {
//            log.info("用户不存在");
//            throw new UsernameNotFoundException("用户不存在");
//        }
//        log.info("查询用户{}", loginUser.getUserName());
//        return new User(loginUser.getUserName(), loginUser.getUserPassword(), emptyList());
        return null;
    }
}
